<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
<!--      <el-form-item label="采购订单id" prop="id">-->
<!--        <el-input-->
<!--          v-model="queryParams.id"-->
<!--          placeholder="请输入采购订单id"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="采购商品" prop="purchaseName">
        <el-input
          v-model="queryParams.purchaseName"
          placeholder="请输入采购商品"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="采购单价" prop="purchasePrice">-->
<!--        <el-input-->
<!--          v-model="queryParams.purchasePrice"-->
<!--          placeholder="请输入采购单价"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="采购数量" prop="purchaseCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.purchaseCount"-->
<!--          placeholder="请输入采购数量"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="采购总额" prop="purchaseMoney">-->
<!--        <el-input-->
<!--          v-model="queryParams.purchaseMoney"-->
<!--          placeholder="请输入采购总额"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="采购厂家" prop="purchaseCompany">
        <el-input
          v-model="queryParams.purchaseCompany"
          placeholder="请输入采购厂家"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="厂家联系人" prop="companyPeople" >
        <el-input
          v-model="queryParams.companyPeople"
          placeholder="请输入厂家联系人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="厂家电话" prop="companyPhone">-->
<!--        <el-input-->
<!--          v-model="queryParams.companyPhone"-->
<!--          placeholder="请输入厂家电话"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="采购人员" prop="purchasePeople">
        <el-select v-model="queryParams.purchasePeople" placeholder="请输入采购人员" clearable size="small">
          <el-option
            v-for="dict in dict.type.zs_purchase_name"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="交货日期" prop="goodTime">-->
<!--        <el-date-picker clearable size="small"-->
<!--          v-model="queryParams.goodTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="选择交货日期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="交易方式" prop="dealType">-->
<!--        <el-select v-model="queryParams.dealType" placeholder="请选择交易方式" clearable size="small">-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.zs_money_type"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="发票" prop="bill">-->
<!--        <el-input-->
<!--          v-model="queryParams.bill"-->
<!--          placeholder="请输入发票"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="支付方式" prop="payTime">-->
<!--        <el-select v-model="queryParams.payTime" placeholder="输入支付方式" clearable size="small">-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.zs_money_type"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="采购部审批人" prop="purchasePass">-->
<!--        <el-select v-model="queryParams.purchasePass" placeholder="请输入采购部审批人" clearable size="small">-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.zs_purchase_caigoubu"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="财务部审批人" prop="moneyPass">-->
<!--        <el-select v-model="queryParams.moneyPass" placeholder="请输入财务部审批人" clearable size="small">-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.zs_purchase_caiwubu"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['purchase:process:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['purchase:process:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['purchase:process:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['purchase:process:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="processList" @selection-change="handleSelectionChange"   style="width: 100%"  >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="采购订单id" align="center" prop="id"   width="70"/>
      <el-table-column label="采购商品" align="center" prop="purchaseName" width="100" fixed/>
      <el-table-column label="型号" align="center" prop="type" width="100"/>
      <el-table-column label="采购单价(元)" align="center" prop="purchasePrice" width="100"/>
      <el-table-column label="采购数量(件)" align="center" prop="purchaseCount" width="100"/>
      <el-table-column label="采购总额(元)" align="center" prop="purchaseMoney" width="100"/>
      <el-table-column label="采购厂家" align="center" prop="purchaseCompany" width="150"/>
      <el-table-column label="厂家联系人" align="center" prop="companyPeople" width="100"/>
      <el-table-column label="厂家电话" align="center" prop="companyPhone" width="150"/>
      <el-table-column label="采购人员" align="center" prop="purchasePeople">
      <template slot-scope="scope">
        <dict-tag :options="dict.type.zs_purchase_name" :value="scope.row.purchasePeople"/>
      </template>
      </el-table-column>
      <el-table-column label="交货日期" align="center" prop="goodTime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.goodTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="交易方式" align="center" prop="dealType" width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zs_money_type" :value="scope.row.dealType"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="发票" align="center" prop="bill" />-->
      <el-table-column label="支付方式" align="center" prop="payTime" >
      <template slot-scope="scope">
        <dict-tag :options="dict.type.zs_pay_type" :value="scope.row.payTime"/>
      </template>
      </el-table-column>
      <el-table-column label="采购部审批人" align="center" prop="purchasePass" >
      <template slot-scope="scope">
        <dict-tag :options="dict.type.zs_purchase_caigoubu" :value="scope.row.purchasePass"/>
      </template>
      </el-table-column>
      <el-table-column label="财务部审批人" align="center" prop="moneyPass" >
      <template slot-scope="scope">
        <dict-tag :options="dict.type.zs_purchase_caiwubu" :value="scope.row.moneyPass"/>
      </template>
      </el-table-column>
      <el-table-column label="其他说明" align="center" prop="other"  width="500"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width"  fixed="right">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['purchase:process:edit']"-->
<!--          >修改</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['purchase:process:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改purchase对话框 -->
<!--    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>-->
<!--      <el-form ref="form" :model="form" :rules="rules" label-width="80px">-->
<!--        <el-form-item label="采购商品" prop="purchaseName">-->
<!--          <el-input v-model="form.purchaseName" placeholder="请输入采购商品" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="采购单价" prop="purchasePrice">-->
<!--          <el-input v-model="form.purchasePrice" placeholder="请输入采购单价" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="采购数量" prop="purchaseCount">-->
<!--          <el-input v-model="form.purchaseCount" placeholder="请输入采购数量" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="采购总额" prop="purchaseMoney">-->
<!--          <el-input v-model="form.purchaseMoney" placeholder="请输入采购总额" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="采购厂家" prop="purchaseCompany">-->
<!--          <el-input v-model="form.purchaseCompany" placeholder="请输入采购厂家" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="厂家联系人" prop="companyPeople">-->
<!--          <el-input v-model="form.companyPeople" placeholder="请输入厂家联系人" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="厂家电话" prop="companyPhone">-->
<!--          <el-input v-model="form.companyPhone" placeholder="请输入厂家电话" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="采购人员" prop="purchasePeople">-->
<!--          <el-input v-model="form.purchasePeople" placeholder="请输入采购人员" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="交货日期" prop="goodTime">-->
<!--          <el-date-picker clearable size="small"-->
<!--            v-model="form.goodTime"-->
<!--            type="date"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            placeholder="选择交货日期">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="交易方式">-->
<!--          <el-radio-group v-model="form.dealType">-->
<!--            <el-radio-->
<!--              v-for="dict in dict.type.zs_money_type"-->
<!--              :key="dict.value"-->
<!--:label="dict.value"-->
<!--            >{{dict.label}}</el-radio>-->
<!--          </el-radio-group>-->
<!--        </el-form-item>-->
<!--&lt;!&ndash;        <el-form-item label="发票" prop="bill">&ndash;&gt;-->
<!--&lt;!&ndash;          <el-input v-model="form.bill" placeholder="请输入发票" />&ndash;&gt;-->
<!--&lt;!&ndash;        </el-form-item>&ndash;&gt;-->
<!--        <el-form-item label="支付方式" prop="payTime">-->
<!--          <el-input v-model="form.payTime" placeholder="请输入支付方式" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="采购部审批人" prop="purchasePass">-->
<!--          <el-input v-model="form.purchasePass" placeholder="请输入采购部审批" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="财务部审批人" prop="moneyPass">-->
<!--          <el-input v-model="form.moneyPass" placeholder="请输入财务部审批" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="其他说明" prop="other">-->
<!--          <el-input v-model="form.other" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
<!--      </el-form>-->
<!--      <div slot="footer" class="dialog-footer">-->
<!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
<!--        <el-button @click="cancel">取 消</el-button>-->
<!--      </div>-->
<!--    </el-dialog>-->
  </div>
</template>

<script>
import { listProcess, getProcess, delProcess, addProcess, updateProcess } from "@/api/purchase/process";

export default {
  name: "Process",
  dicts: ['zs_money_type', 'zs_pay_type', 'zs_purchase_name', 'zs_purchase_caiwubu', 'zs_purchase_caigoubu',],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // purchase表格数据
      processList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        purchaseName: null,
        type: null,
        purchasePrice: null,
        purchaseCount: null,
        purchaseMoney: null,
        purchaseCompany: null,
        companyPeople: null,
        companyPhone: null,
        purchasePeople: null,
        goodTime: null,
        dealType: null,
        bill: null,
        payTime: null,
        purchasePass: null,
        moneyPass: null,
        other: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "采购订单id不能为空", trigger: "blur" }
        ],
        purchaseName: [
          { required: true, message: "采购商品不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "型号不能为空", trigger: "change" }
        ],
        purchasePeople: [
          { required: true, message: "采购人员不能为空", trigger: "blur" }
        ],
        purchasePass: [
          { required: true, message: "采购部审批不能为空", trigger: "blur" }
        ],
        moneyPass: [
          { required: true, message: "财务部审批不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询purchase列表 */
    getList() {
      this.loading = true;
      listProcess(this.queryParams).then(response => {
        this.processList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        purchaseName: null,
        type: null,
        purchasePrice: null,
        purchaseCount: null,
        purchaseMoney: null,
        purchaseCompany: null,
        companyPeople: null,
        companyPhone: null,
        purchasePeople: null,
        goodTime: null,
        dealType: null,
        bill: null,
        payTime: null,
        purchasePass: null,
        moneyPass: null,
        other: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加purchase";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getProcess(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改purchase";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProcess(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProcess(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除purchase编号为"' + ids + '"的数据项？').then(function() {
        return delProcess(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('purchase/process/export', {
        ...this.queryParams
      }, `process_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
